#!/usr/bin/env coffee

nodemailer = require 'nodemailer'
{SMTP, SENDER} = require('../config/smtp')
transporter = nodemailer.createTransport(SMTP)

# https://help.aliyun.com/document_detail/29456.html
module.exports = (mail)->
    mail = Object.assign({}, SENDER, mail)

    if mail.from_name
        mail.from = "#{mail.from_name}<#{mail.from}>"
        delete mail.from_name

    if mail.to_name
        mail.to = "#{mail.to_name}<#{mail.to}>"
        delete mail.to_name

    await transporter.sendMail(mail)


